package com.shy.config.handler;

import com.shy.config.model.R;
import com.shy.config.util.BusinessException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常类
 */
@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {
    /**
     * 处理自定义业务异常：精确
     * @param e 异常
     * @return 异常信息
     */
    @ExceptionHandler(BusinessException.class)
    public R<String> handleBusinessException(BusinessException e) {
        e.printStackTrace();
        return R.failure(e.getMessage());
    }

    /**
     * 全局异常处理
     * @param e 异常
     * @return 异常信息
     */
    @ExceptionHandler(Exception.class)
    public R<String> handleException(Exception e) {
       e.printStackTrace();
        return R.failure(e.getMessage());
    }
}
